home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1869 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  79 lines

  1. Newsgroups: comp.lang.c
  2. Path: gail.ripco.com!mambuhl
  3. From: mambuhl@ripco.com (Martin Ambuhl)
  4. Subject: Re: HELP: What is wrong ?
  5. X-Nntp-Posting-Host: foley.ripco.com
  6. Message-ID: <DLBpyB.5D5@rci.ripco.com>
  7. Sender: usenet@rci.ripco.com (Net News Admin)
  8. Organization: Ripco Internet BBS Chicago
  9. Date: Wed, 17 Jan 1996 11:44:35 GMT
  10. X-Ident-Sender: mambuhl
  11.  
  12. jinsoo@etri.re.kr (Jin-Soo Lee)
  13. in <4df373$kd3@ns.etri.re.kr> asks:
  14.  
  15. > Your KIND HELP is needed.
  16. > I have some problems in the following code.
  17.  
  18. >---------
  19.  
  20. >#define DSKPAGESIZE     16*1024
  21. >#define LOGBUFSIZE      2*DSKPAGESIZE
  22.  
  23. The above #defines are almost certainly wrong.  Replace them with
  24. #define DSKPAGESIZE     (16*1024)
  25. #define LOGBUFSIZE      (2*DSKPAGESIZE)
  26.  
  27. Below I have shown what your lines look like after the token replacement
  28. is done with your original #defines.  I think you will see that they are not
  29. what you wanted.
  30.  
  31.  
  32. >main()
  33. >{
  34. >        int     pageBS, logoffset, bufferoffset, buffersize, length;
  35. >        int     freespace, inusefile;
  36. >        char    *globla_page;
  37. >        T_LOGRECORD     *tlogrec;
  38. >....
  39. >(1)     pageBS = (logoffset/LOGBUFSIZE) * LOGBUFSIZE;
  40.    pageBS = (logoffset/2*16*1024  ) * 2*16*1024  ;
  41.  
  42. >....
  43. >(2)     bufferoffset = (logoffset + length)%LOGBUFSIZE;
  44.    bufferoffset = (logoffset + length)%2*16*1024  ;
  45.  
  46. >....
  47. >(3)     tlogrec = (T_LOGRECORD *)(global_page + (logoffset%LOGBUFSIZE));
  48.    tlogrec = (T_LOGRECORD *)(global_page + (logoffset%2*16*1024  ));
  49.  
  50. >....
  51. >        freespace = inuselogfile - logoffset;
  52. >(4)     if (freespace - length > sizeof(int))
  53. >....
  54. >        freespace = buffersize - bufferoffset;
  55. >(5)     if (freespace - length >= sizeof(int))
  56. >....
  57. >}
  58.  
  59. >---------
  60.  
  61. > The code worked well on SUN OS 4.1.3. and K&R C with dbx,
  62. Then either those compilers were broken or you just never noticed the problems.
  63.  
  64. > but goes wrong when moved to current environment,
  65. > Solaris 2.4 and SUN C with SparcWorks dbx and gcc with gdb.
  66. > The statements (1) ~ (5) sometimes make too big or negative values.
  67. > I can't believe it.
  68. > What happened ?
  69. > OS or compiler problem ? or C language syntax problem ?
  70.  
  71. Neither.  The problem is with your code.
  72.  
  73. > Any help is greatly appreciated. Please e-mail me.
  74.                                    ^^^^^^^^^^^^^^^^^ Eat  me.
  75.            
  76. --
  77. * Martin Ambuhl       net: mambuhl@ripco.com
  78. * Chicago, IL (USA)    
  79.